﻿<UserControl
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:Custom="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
    xmlns:GameLogic_Logic="clr-namespace:GameLogic.Logic;assembly=GameLogic"
    xmlns:il="clr-namespace:Microsoft.Expression.Interactivity.Layout;assembly=Microsoft.Expression.Interactions"
    xmlns:im="clr-namespace:Microsoft.Expression.Interactivity.Media;assembly=Microsoft.Expression.Interactions"
    mc:Ignorable="d"
    x:Class="Dodger.DodgerGame"
    d:DesignWidth="480"
    d:DesignHeight="800"
    Height="800"
    Width="480">

    <Canvas
		x:Name="LayoutRoot"
		Background="#FF282041">
		<Custom:Interaction.Behaviors>
			<GameLogic_Logic:GameLoop />
		</Custom:Interaction.Behaviors>
		<Custom:Interaction.Triggers>
			<GameLogic_Logic:GameLoopTickTrigger
				SourceName="LayoutRoot">
				<!--
                <GameLogic_Logic:ChangeGamePropertiesAction
                    ChangeScoresOnAction="True"
                    ScoresIncrementValue="1" />
                -->
			</GameLogic_Logic:GameLoopTickTrigger>
			<GameLogic_Logic:GameLoopTickTrigger>
				<GameLogic_Logic:ChangeGamePropertiesAction ChangeScoresOnAction="True" ScoresIncrementValue="1"/>
			</GameLogic_Logic:GameLoopTickTrigger>
			<GameLogic_Logic:CollisionTrigger SourceName="_player">
	<!--
                    <GameLogic_Logic:ChangeGamePropertiesAction
                        ChangeLivesOnAction="True"
                        LivesIncrementValue="-1" />
                    -->
				<im:PlaySoundAction Source="/lostLife.mp3" Volume="1"/>
			</GameLogic_Logic:CollisionTrigger>
			<GameLogic_Logic:CollisionTrigger SourceName="_enemy1">
				<im:PlaySoundAction Source="/wall.mp3" Volume="1"/>
			</GameLogic_Logic:CollisionTrigger>
			<GameLogic_Logic:CollisionTrigger SourceName="_enemy5">
				<im:PlaySoundAction Source="/wall.mp3" Volume="1"/>
			</GameLogic_Logic:CollisionTrigger>
			<GameLogic_Logic:CollisionTrigger SourceName="_enemy4">
				<im:PlaySoundAction Source="/wall.mp3" Volume="1"/>
			</GameLogic_Logic:CollisionTrigger>
			<GameLogic_Logic:CollisionTrigger SourceName="_enemy3">
				<im:PlaySoundAction Source="/wall.mp3" Volume="1"/>
			</GameLogic_Logic:CollisionTrigger>
			<GameLogic_Logic:CollisionTrigger SourceName="_enemy2">
				<im:PlaySoundAction Source="/wall.mp3" Volume="1"/>
			</GameLogic_Logic:CollisionTrigger>
		</Custom:Interaction.Triggers>
		<VisualStateManager.VisualStateGroups>
			<VisualStateGroup
				x:Name="GameStates">
				<VisualState
					x:Name="Playing">
					<Storyboard>
						<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="_gameReadyMessage">
							<DiscreteObjectKeyFrame KeyTime="0">
								<DiscreteObjectKeyFrame.Value>
									<Visibility>Collapsed</Visibility>
								</DiscreteObjectKeyFrame.Value>
							</DiscreteObjectKeyFrame>
						</ObjectAnimationUsingKeyFrames>
						<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="_lifeLostMessage">
							<DiscreteObjectKeyFrame KeyTime="0">
								<DiscreteObjectKeyFrame.Value>
									<Visibility>Collapsed</Visibility>
								</DiscreteObjectKeyFrame.Value>
							</DiscreteObjectKeyFrame>
						</ObjectAnimationUsingKeyFrames>
					</Storyboard>
				</VisualState>
				<VisualState
					x:Name="LifeLost">
					<Storyboard>
						<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="_gameReadyMessage">
							<DiscreteObjectKeyFrame KeyTime="0">
								<DiscreteObjectKeyFrame.Value>
									<Visibility>Collapsed</Visibility>
								</DiscreteObjectKeyFrame.Value>
							</DiscreteObjectKeyFrame>
						</ObjectAnimationUsingKeyFrames>
						<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="_lifeLostMessage">
							<DiscreteObjectKeyFrame KeyTime="0">
								<DiscreteObjectKeyFrame.Value>
									<Visibility>Visible</Visibility>
								</DiscreteObjectKeyFrame.Value>
							</DiscreteObjectKeyFrame>
						</ObjectAnimationUsingKeyFrames>
					</Storyboard>
				</VisualState>
				<VisualState x:Name="GameReady">
					<Storyboard>
						<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="_gameReadyMessage">
							<DiscreteObjectKeyFrame KeyTime="0">
								<DiscreteObjectKeyFrame.Value>
									<Visibility>Visible</Visibility>
								</DiscreteObjectKeyFrame.Value>
							</DiscreteObjectKeyFrame>
						</ObjectAnimationUsingKeyFrames>
						<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="_lifeLostMessage">
							<DiscreteObjectKeyFrame KeyTime="0">
								<DiscreteObjectKeyFrame.Value>
									<Visibility>Collapsed</Visibility>
								</DiscreteObjectKeyFrame.Value>
							</DiscreteObjectKeyFrame>
						</ObjectAnimationUsingKeyFrames>
					</Storyboard>
				</VisualState>
			</VisualStateGroup>
		</VisualStateManager.VisualStateGroups>
		<Rectangle
			x:Name="_left"
			Width="10"
			Fill="#4C000000"
			Canvas.ZIndex="3" Height="800">
			<Custom:Interaction.Behaviors>
				<GameLogic_Logic:StaticCollidableBehavior />
			</Custom:Interaction.Behaviors>
		</Rectangle>
		<Rectangle
			x:Name="_right"
			Width="10"
			Fill="#4C000000"
			Canvas.ZIndex="3" Height="800" Canvas.Left="470">
			<Custom:Interaction.Behaviors>
				<GameLogic_Logic:StaticCollidableBehavior />
			</Custom:Interaction.Behaviors>
		</Rectangle>
		<Rectangle
			x:Name="_top"
			Height="10"
			Fill="#4C000000"
			Canvas.ZIndex="3" Width="480">
			<Custom:Interaction.Behaviors>
				<GameLogic_Logic:StaticCollidableBehavior />
			</Custom:Interaction.Behaviors>
		</Rectangle>
		<Rectangle
			x:Name="_bottom"
			Height="10"
			Fill="#4C000000"
			Canvas.ZIndex="3" Canvas.Top="790" Width="480">
			<Custom:Interaction.Behaviors>
				<GameLogic_Logic:StaticCollidableBehavior />
			</Custom:Interaction.Behaviors>
		</Rectangle>
		<Rectangle
			x:Name="_enemy1"
			Height="50"
			Width="50"
			RadiusX="2"
			RadiusY="2"
			StrokeThickness="2"
			Canvas.ZIndex="2" Canvas.Left="60" Canvas.Top="69">
			<Custom:Interaction.Behaviors>
				<GameLogic_Logic:MovingCollidableBehavior
					CollisionEnabled="True"
					CollisionType="Bounce"
					AutoStart="True"
					Direction="80"
					Speed="2" />
			</Custom:Interaction.Behaviors>
			<Rectangle.Fill>
				<LinearGradientBrush
					EndPoint="0.5,1"
					StartPoint="0.5,0">
					<GradientStop
						Color="#4C000000"
						Offset="0" />
					<GradientStop
						Color="#CC000000"
						Offset="1" />
				</LinearGradientBrush>
			</Rectangle.Fill>
			<Rectangle.Stroke>
				<LinearGradientBrush
					EndPoint="0.5,1"
					MappingMode="RelativeToBoundingBox"
					StartPoint="0.5,0">
					<GradientStop
						Color="Black"
						Offset="0" />
					<GradientStop
						Color="#FFCC1F1F"
						Offset="1" />
				</LinearGradientBrush>
			</Rectangle.Stroke>
		</Rectangle>
		<Rectangle
			x:Name="_enemy2"
			Height="50"
			Width="50"
			RadiusX="2"
			RadiusY="2"
			StrokeThickness="2"
			Canvas.ZIndex="2" Canvas.Left="356" Canvas.Top="103">
			<Custom:Interaction.Triggers>
				<GameLogic_Logic:CollisionTrigger>
					<im:PlaySoundAction Source="/wall.mp3" Volume="1"/>
				</GameLogic_Logic:CollisionTrigger>
			</Custom:Interaction.Triggers>
			<Custom:Interaction.Behaviors>
				<GameLogic_Logic:MovingCollidableBehavior
					CollisionEnabled="True"
					CollisionType="Bounce"
					AutoStart="True"
					Direction="12"
					Speed="4" />
			</Custom:Interaction.Behaviors>
			<Rectangle.Fill>
				<LinearGradientBrush
					EndPoint="0.5,1"
					StartPoint="0.5,0">
					<GradientStop
						Color="#4C000000"
						Offset="0" />
					<GradientStop
						Color="#CC000000"
						Offset="1" />
				</LinearGradientBrush>
			</Rectangle.Fill>
			<Rectangle.Stroke>
				<LinearGradientBrush
					EndPoint="0.5,1"
					MappingMode="RelativeToBoundingBox"
					StartPoint="0.5,0">
					<GradientStop
						Color="Black"
						Offset="0" />
					<GradientStop
						Color="#FFCC1F1F"
						Offset="1" />
				</LinearGradientBrush>
			</Rectangle.Stroke>
		</Rectangle>
		<Rectangle
			x:Name="_enemy3"
			Height="50"
			Width="50"
			RadiusX="2"
			RadiusY="2"
			StrokeThickness="2"
			Canvas.ZIndex="2" Canvas.Left="60" Canvas.Top="543">
			<Custom:Interaction.Triggers>
				<GameLogic_Logic:CollisionTrigger>
					<im:PlaySoundAction Source="/wall.mp3" Volume="1"/>
				</GameLogic_Logic:CollisionTrigger>
			</Custom:Interaction.Triggers>
			<Custom:Interaction.Behaviors>
				<GameLogic_Logic:MovingCollidableBehavior
					CollisionEnabled="True"
					CollisionType="Bounce"
					AutoStart="True"
					Direction="133"
					Speed="4" />
			</Custom:Interaction.Behaviors>
			<Rectangle.Fill>
				<LinearGradientBrush
					EndPoint="0.5,1"
					StartPoint="0.5,0">
					<GradientStop
						Color="#4C000000"
						Offset="0" />
					<GradientStop
						Color="#CC000000"
						Offset="1" />
				</LinearGradientBrush>
			</Rectangle.Fill>
			<Rectangle.Stroke>
				<LinearGradientBrush
					EndPoint="0.5,1"
					MappingMode="RelativeToBoundingBox"
					StartPoint="0.5,0">
					<GradientStop
						Color="Black"
						Offset="0" />
					<GradientStop
						Color="#FFCC1F1F"
						Offset="1" />
				</LinearGradientBrush>
			</Rectangle.Stroke>
		</Rectangle>
		<Rectangle
			x:Name="_enemy4"
			Height="50"
			RadiusX="2"
			RadiusY="2"
			StrokeThickness="2"
			Width="50"
			Canvas.ZIndex="2" Canvas.Left="356" Canvas.Top="606">
			<Custom:Interaction.Behaviors>
				<GameLogic_Logic:MovingCollidableBehavior
					CollisionEnabled="True"
					CollisionType="Bounce"
					AutoStart="True"
					Direction="34"
					Speed="4" />
			</Custom:Interaction.Behaviors>
			<Rectangle.Fill>
				<LinearGradientBrush
					EndPoint="0.5,1"
					StartPoint="0.5,0">
					<GradientStop
						Color="#4C000000"
						Offset="0" />
					<GradientStop
						Color="#CC000000"
						Offset="1" />
				</LinearGradientBrush>
			</Rectangle.Fill>
			<Rectangle.Stroke>
				<LinearGradientBrush
					EndPoint="0.5,1"
					MappingMode="RelativeToBoundingBox"
					StartPoint="0.5,0">
					<GradientStop
						Color="Black"
						Offset="0" />
					<GradientStop
						Color="#FFCC1F1F"
						Offset="1" />
				</LinearGradientBrush>
			</Rectangle.Stroke>
		</Rectangle>
		<Rectangle
			x:Name="_enemy5"
			Height="50"
			RadiusX="2"
			RadiusY="2"
			StrokeThickness="2"
			Width="50"
			d:LayoutOverrides="HorizontalAlignment, Width"
			Canvas.ZIndex="2" Canvas.Left="215" Canvas.Top="705">
			<Custom:Interaction.Behaviors>
				<GameLogic_Logic:MovingCollidableBehavior
					CollisionEnabled="True"
					CollisionType="Bounce"
					AutoStart="True"
					Direction="55"
					Speed="4" />
			</Custom:Interaction.Behaviors>
			<Rectangle.Fill>
				<LinearGradientBrush
					EndPoint="0.5,1"
					StartPoint="0.5,0">
					<GradientStop
						Color="#4C000000"
						Offset="0" />
					<GradientStop
						Color="#CC000000"
						Offset="1" />
				</LinearGradientBrush>
			</Rectangle.Fill>
			<Rectangle.Stroke>
				<LinearGradientBrush
					EndPoint="0.5,1"
					MappingMode="RelativeToBoundingBox"
					StartPoint="0.5,0">
					<GradientStop
						Color="Black"
						Offset="0" />
					<GradientStop
						Color="#FFCC1F1F"
						Offset="1" />
				</LinearGradientBrush>
			</Rectangle.Stroke>
		</Rectangle>
		<Rectangle
			x:Name="_player"
			Height="50"
			VerticalAlignment="Center"
			RadiusX="2"
			RadiusY="2"
			StrokeThickness="2"
			RenderTransformOrigin="-2.2,1.5"
			HorizontalAlignment="Center"
			Width="50"
			Canvas.ZIndex="1" Canvas.Left="215" Canvas.Top="375">
			<Custom:Interaction.Triggers>
				<GameLogic_Logic:CollisionTrigger>
					<GameLogic_Logic:ChangeGamePropertiesAction ChangeLivesOnAction="True" LivesIncrementValue="-1"/>
					<!--
                    <GameLogic_Logic:ChangeGamePropertiesAction
                        ChangeLivesOnAction="True"
                        LivesIncrementValue="-1" />
                    -->
				</GameLogic_Logic:CollisionTrigger>
			</Custom:Interaction.Triggers>
			<Custom:Interaction.Behaviors>
				<GameLogic_Logic:StaticCollidableBehavior />
				<il:MouseDragElementBehavior ConstrainToParentBounds="True"/>
			</Custom:Interaction.Behaviors>
			<Rectangle.Fill>
				<LinearGradientBrush
					EndPoint="0.5,1"
					StartPoint="0.5,0">
					<GradientStop
						Color="#4CFF7602"
						Offset="0" />
					<GradientStop
						Color="#CCFF7602"
						Offset="1" />
				</LinearGradientBrush>
			</Rectangle.Fill>
			<Rectangle.Stroke>
				<LinearGradientBrush
					EndPoint="0.5,1"
					MappingMode="RelativeToBoundingBox"
					StartPoint="0.5,0">
					<GradientStop
						Color="#FF7C4C35"
						Offset="0" />
					<GradientStop
						Color="#FF1F1C1B"
						Offset="1" />
				</LinearGradientBrush>
			</Rectangle.Stroke>
		</Rectangle>
		<Grid x:Name="_lifeLostMessage" Height="800" Width="480" Background="#33000000" Canvas.ZIndex="3">
			<Border
				BorderBrush="Black"
				BorderThickness="2"
				CornerRadius="2"
				Background="#33040303"
				Canvas.ZIndex="4"
				Margin="0"
				Padding="10" HorizontalAlignment="Center" VerticalAlignment="Center">
				<StackPanel
					Orientation="Vertical">
					<TextBlock
						TextWrapping="Wrap"
						Text="Don't touch the moving boxes!"
						Canvas.ZIndex="4"
						FontSize="32"
						HorizontalAlignment="Center"
						VerticalAlignment="Center"
						Foreground="#FFFBFBFB" TextAlignment="Center" />
					<Button
						x:Name="_continue"
						Content="Continue"
						HorizontalAlignment="Center"
						Click="_continue_Click" >
						<Custom:Interaction.Triggers>
							<Custom:EventTrigger EventName="Click">
								<im:PlaySoundAction Source="/start.mp3" Volume="1"/>
							</Custom:EventTrigger>
						</Custom:Interaction.Triggers>
					</Button>
				</StackPanel>
			</Border>
		</Grid>
		<Grid x:Name="_gameReadyMessage" Background="#66000000" Canvas.ZIndex="3" Height="800" Width="480">
			<Border
				HorizontalAlignment="Center"
				VerticalAlignment="Center"
				BorderBrush="Black"
				BorderThickness="2"
				CornerRadius="2"
				Background="#33040303"
				Canvas.ZIndex="4"
				Margin="0"
				Padding="10">
				<StackPanel
					Orientation="Vertical">
					<TextBlock
						TextWrapping="Wrap"
						Text="Dodge the moving boxes!"
						Canvas.ZIndex="4"
						FontSize="32"
						Height="47"
						HorizontalAlignment="Center"
						VerticalAlignment="Center"
						Foreground="#FFFBFBFB" TextAlignment="Center" />
					<Button
						x:Name="_startGame"
						Content="Start Game"
						HorizontalAlignment="Center"
						Click="_startGame_Click" >
						<Custom:Interaction.Triggers>
							<Custom:EventTrigger EventName="Click">
								<im:PlaySoundAction Source="/start.mp3" Volume="1"/>
							</Custom:EventTrigger>
						</Custom:Interaction.Triggers>
					</Button>
				</StackPanel>
			</Border>
		</Grid>
	</Canvas>
</UserControl>